package com.aspire.moss.portal.view;

import java.util.Observable;
import java.util.Observer;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;

import com.aspire.moss.portal.R;
/**
 * 第一个单元格的内容,实现Observer观察workspace里的WorkspaceLock的变化,显示或者隐藏删除程序图标
 * @author Administrator
 *
 */
public class CellView extends RelativeLayout implements Observer , OnClickListener{
	
	private static final String TAG = "CellView";

	public AppInfo appInfo; //保存当前的单元格信息
	
	/**
	 * 自己的点击事件
	 */
	private OnClickListener onClickListener; 
	
	/**
	 * 删除图标的点事件
	 */
	private OnDeleteClickListener onDeleteClickListener;
	
	public CellView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	/**
	 * 更新状态是否可以点击删除图标和自己
	 */
	@Override
	public void update(Observable observable, Object data) {
		Log.d(TAG, "update(Observable observable, Object data) data=" + data);
		if(null !=data && data instanceof Boolean){
			Boolean con = (Boolean) data;
			if(con){
				findViewById(R.id.delteicon).setVisibility(View.VISIBLE);
				setClickable(false);
				super.setOnClickListener(null);
			}else{
				findViewById(R.id.delteicon).setVisibility(View.GONE);
				setClickable(true);
				super.setOnClickListener(onClickListener);
			}
		}
	}

	public OnClickListener getOnClickListener() {
		return onClickListener;
	}

	public void setOnClickListener(OnClickListener onClickListener) {
		this.onClickListener = onClickListener;
		super.setOnClickListener(this.onClickListener);
	}

	public OnDeleteClickListener getOnDeleteClickListener() {
		return onDeleteClickListener;
	}

	public void setOnDeleteClickListener(OnDeleteClickListener onDeleteClickListener) {
		this.onDeleteClickListener = onDeleteClickListener;
		if (null != onDeleteClickListener) {
			View delete = findViewById(R.id.delteicon);
			if(null != delete){
				delete.setOnClickListener(this);
			}
		}
	}

	@Override
	public void onClick(View v) {
		onDeleteClickListener.onDeleteClick(CellView.this);
	}
	
	/**
	 * 点击删除图标的事件接口
	 * @author Administrator
	 *
	 */
	public interface OnDeleteClickListener {
		
		void onDeleteClick(CellView view);
		
	}

}
